package com.cts.security;

public class InsertionSort {
	public static void main(String a[]) {
		int array[] = { 12, 9, 4, 99, 120, 1, 3, 10 };
//		printArray(array, "before");
		bubbleSort(array, array.length);
//		printArray(array, "after");
	}

	public static void bubbleSort(int array[], int n) {
		int i, j, t = 0;
		for (i = 0; i < n; i++) {
			for (j = 1; j < (n - i); j++) {
				if (array[j - 1] > array[j]) {
					t = array[j - 1];
					array[j - 1] = array[j];
					array[j] = t;
				}
			}
		}
	}

	public static void insertionSort(int array[], int n) {
		for (int i = 1; i < n; i++) {
			int j = i;
			int B = array[i];
			while ((j > 0) && (array[j - 1] > B)) {
				array[j] = array[j - 1];
				j--;
			}
			array[j] = B;
		}
	}

	/*private static void printArray(int array[], String message) {
		int i;
		System.out.print("Values " + message + " the sort:\n");
		for (i = 0; i < array.length; i++)
			System.out.print(array[i] + "  ");
		System.out.println();
	}*/
}